﻿NExt.UI.Base.Right.CompositeRightSetter = Ext.extend(NExt.UI.Base.Right.RightSetter, {
    rightSetterList: [],

    subscribeToInnerRightSettersEvent: function() {
        for (i = 0; i < this.rightSetterList.length; i++) {
            this.rightSetterList[i].on('needRefresh', this.onRightSetterElementNeedRefreshInvoked, this);
        }

        this.eventinit = true;
    },

    onRightSetterElementNeedRefreshInvoked: function() {
        this.fireEvent('needRefresh');
    },

    isEnabled: function(action) {
        if (!this.eventinit) {
            this.subscribeToInnerRightSettersEvent();
        }

        var enabled;
        for (i = 0; i < this.rightSetterList.length; i++) {
            var currentEnabled = this.rightSetterList[i].isEnabled(action);

            if (Ext.isDefined(currentEnabled)) {
                enabled = Ext.isDefined(enabled) ? enabled : true;
                enabled = currentEnabled && enabled;
            }
        }

        return enabled;
    }
});